package coba.mailing.function;

import java.util.Calendar;
import java.util.Date;

public class NextXday {

	public static Date nextXday(int dayOfWeek, Date today) {

		Calendar now = Calendar.getInstance();
		now.setTime(today);

		int weekday = now.get(Calendar.DAY_OF_WEEK);

		if (weekday != dayOfWeek) {
			int days = (Calendar.SATURDAY - weekday + dayOfWeek) % 7;
			now.add(Calendar.DAY_OF_YEAR, days);
		}

		return now.getTime();

	}

}
